home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 019a / view002.zip / VIEWGEN.C < prev    next >
C/C++ Source or Header  |  1991-09-13  |  2KB  |  124 lines

  1. /*
  2. View 0.02 - A simple,small,windowed, text file viewer.
  3.  
  4. Copyright (c) 1991 James P. Goodwin.
  5. All rights reserved.
  6.  
  7. Redistribution and use in source and binary forms are per-
  8. mitted provided that the above copyright notice is dupli-
  9. cated in all such forms and that any documentation,
  10. advertising materials, and other materials related to such
  11. distribution and use acknowledge that the software was
  12. developed by James P. Goodwin.
  13.  
  14. THE SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS
  15. OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE
  16. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PAR-
  17. TICULAR PURPOSE.
  18. */
  19.  
  20.  
  21. #include <stdio.h>
  22. #include <fcntl.h>
  23. #include <sys\types.h>
  24. #include <sys\stat.h>
  25. #include <io.h>
  26. #include <share.h>
  27. #include <stdlib.h>
  28. #include <string.h>
  29. #include <dos.h>
  30. #include <share.h>
  31. #include <conio.h>
  32. #include <limits.h>
  33. #include <direct.h>
  34. #include "view.h"
  35.  
  36. /*
  37.   View General purpose routines
  38. */
  39. void view_error( int isfatal,UCHAR *msg )
  40. {
  41.   int col;
  42.   int len;
  43.   VIEWSAVE *save;
  44.  
  45.   len = max(40,strlen(msg));
  46.   col = 40-(len/2);
  47.  
  48.   if (!isfatal)
  49.     save = view_getsave(11,col-1,3,len+2);
  50.  
  51.   view_attr = ERROR_MESSAGE;
  52.   view_frame("Error - Press <ENTER>",11,col-1,3,len+2);
  53.   view_goto(12,col);
  54.   view_puts(msg,len);
  55.  
  56.   if (!getch()) getch();
  57.  
  58.   if (isfatal)
  59.     exit(1);
  60.   else
  61.     view_putsave(save);
  62. }
  63.  
  64. int max( int x, int y)
  65. {
  66.   return(((x < y) ? y : x));
  67. }
  68.  
  69. int min ( int x, int y)
  70. {
  71.   return(((x < y) ? x : y));
  72. }
  73.  
  74. #if VIEW_HAS_RAW 
  75. UCHAR *view_ultoa( ULONG num, int base, int wide, int fill )
  76. {
  77.    static char workbuf[VIEW_MAX_LONG];
  78.    int work;
  79.    int idx;
  80.  
  81.    workbuf[VIEW_MAX_LONG-1] = '\0';
  82.  
  83.    for (idx = VIEW_MAX_LONG-1; num && idx ;)
  84.      {
  85.      wide --;
  86.      idx  --;
  87.      workbuf[idx] = hexdigits[num%base];
  88.      num /= base;
  89.      }
  90.  
  91.    while( wide > 0  && idx )
  92.      {
  93.      idx --;
  94.      wide --;
  95.      workbuf[idx] = fill;
  96.      }
  97.  
  98.    return(workbuf+idx);
  99. }
  100. #endif
  101.  
  102. #if VIEW_HAS_GOTO
  103. ULONG view_atoul( UCHAR *num, int base )
  104. {
  105.    int idx,jdx;
  106.    ULONG val;
  107.  
  108.    val = 0;
  109.  
  110.    while( *num )
  111.      {
  112.      for (jdx = 0; hexdigits[jdx] && hexdigits[jdx] != *num; jdx ++);
  113.  
  114.      if (!hexdigits[jdx]) break;
  115.  
  116.      val *= base;
  117.      val += jdx;
  118.      num ++;
  119.      }
  120.  
  121.    return(val);
  122. }
  123. #endif /* VIEW_HAS_GOTO */
  124.